//
//  SDHSportsAboutVC.m
//  SDHSportsNews
//
//  Created by MichaelShan on 2021/3/15.
//

#import "SDHSportsAboutVC.h"
#import "SDHSportsNotchScreenUtil.h"

@interface SDHSportsAboutVC () <UITableViewDelegate, UITableViewDataSource>

@end

@implementation SDHSportsAboutVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"About Us";
    self.view.backgroundColor = UIColorFromRGB(48, 48, 48);
    [self initUI];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    self.navigationController.navigationBar.hidden = YES;
}

- (void)initUI {
    
    UIView *hView = [UIView new];
    [self.view addSubview:hView];
    
    CGFloat statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
    CGFloat navHeight = self.navigationController.navigationBar.frame.size.height;
    CGFloat notchHeight = [SDHSportsNotchScreenUtil getIPhoneNotchScreenHeight];
    notchHeight = 0;
    CGFloat posY =  statusBarHeight + navHeight + notchHeight + 50;
    
    [hView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(posY);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    
    UIImageView *imgIcon = [UIImageView new];
    imgIcon.backgroundColor = [UIColor redColor];
    [hView addSubview:imgIcon];
    NSDictionary *infoPlist = [[NSBundle mainBundle] infoDictionary];
    NSString *icon = [[infoPlist valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject];
    UIImage *iconImage = [UIImage imageNamed:icon];
    imgIcon.image = iconImage;
    
    UILabel *nameLb = [UILabel new];
    nameLb.textColor = [UIColor whiteColor];
    nameLb.font = [UIFont systemFontOfSize:16];
    nameLb.textAlignment = NSTextAlignmentLeft;
    [hView addSubview:nameLb];
        
    UILabel *versionLb = [UILabel new];
    versionLb.textColor = [UIColor whiteColor];
    versionLb.font = [UIFont systemFontOfSize:16];
    versionLb.textAlignment = NSTextAlignmentLeft;
    [hView addSubview:versionLb];

    UILabel *contactUsLb = [UILabel new];
    contactUsLb.textColor = [UIColor whiteColor];
    contactUsLb.font = [UIFont systemFontOfSize:16];
    contactUsLb.textAlignment = NSTextAlignmentLeft;
    [hView addSubview:contactUsLb];
    
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    // app名称
    NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
    // app版本
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    
    nameLb.text = [NSString stringWithFormat:@"Name: %@", app_Name];
    versionLb.text = [NSString stringWithFormat:@"Version: v%@", app_Version];
    contactUsLb.text = [NSString stringWithFormat:@"Contact: gamesort@126.com"];
    [imgIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.mas_equalTo(10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(50);
    }];
    
    [nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imgIcon).offset(-50);
        make.top.equalTo(imgIcon.mas_bottom).offset(10);
        make.width.mas_equalTo(300);
    }];
    
    [versionLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameLb);
        make.top.equalTo(nameLb.mas_bottom).offset(10);
        make.width.equalTo(nameLb);
    }];
    
    [contactUsLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameLb);
        make.top.equalTo(versionLb.mas_bottom).offset(10);
        make.width.equalTo(nameLb);
    }];
}

@end
